﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Text;

namespace eTraining.PageProcess
{
    class demoIndex : PageProcessBase
    {
        public override Uri URI
        {
            get
            {
                string path = @"file:///" + Application.StartupPath + @"/../../html/index.html";
                //Console.WriteLine(u.ToString());
                return new Uri(path);
            }
        }

        protected override void Process(WebBrowserDocumentCompletedEventArgs e)
        {
            WB.Document.All["user"].SetAttribute("value", "Guest");
            WB.Document.All["user"].InvokeMember("select");
            WB.Document.All["user"].Focus();
            WB.Document.All["user"].KeyDown += new HtmlElementEventHandler(demoIndex_KeyDown);
            WB.Document.All["user"].Focusing += new HtmlElementEventHandler(demoIndex_Focusing);
            WB.Document.All["LogInA"].Click += new HtmlElementEventHandler(demoIndex_Click);
            WB.Document.All["Try"].Click +=new HtmlElementEventHandler(Try_Click);
        }

        void Try_Click(object sender, HtmlElementEventArgs e)
        {
            e.ReturnValue = false;
            string name = WB.Document.All["user"].GetAttribute("value").ToString();
            LogIn(name,false);
        }

        void demoIndex_Focusing(object sender, HtmlElementEventArgs e)
        {
            WB.Document.All["user"].InvokeMember("select");
            WB.Document.All["user"].Focus();
        }

        void demoIndex_KeyDown(object sender, HtmlElementEventArgs e)
        {
            if (e.KeyPressedCode == 13)
            {
                e.ReturnValue = false;
                string name = WB.Document.All["user"].GetAttribute("value").ToString();
                LogIn(name,true);
            }
        }

        void demoIndex_Click(object sender, HtmlElementEventArgs e)
        {
            e.ReturnValue = false;
            string name = WB.Document.All["user"].GetAttribute("value").ToString();
            LogIn(name,true);
        }

        private void LogIn(string name ,bool flg)
        {
            Form frm = null;
            frm = new frmLogin();
            frm.ShowDialog();
            WB.Navigate(WB.Document.All["LogInA"].GetAttribute("href").ToString());
        }
    }
}
